package com.soul.server.controller;

import com.soul.model.vo.MovementVo;
import com.soul.model.vo.MovementsVo;
import com.soul.model.vo.PageResult;
import com.soul.server.server.MovementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;

/**
 * @author mdoya
 * @version 1.0
 * @description: 圈子控制层
 */
@Slf4j
@RestController
@RequestMapping("/movements")
public class MovementController {

    @Autowired
    private MovementService movementService;

    /**
     * 圈子-用户发布动态
     *
     * @param movementVo   参数
     * @param imageContent 图片数组
     * @return null
     */
    @PostMapping
    public ResponseEntity addMovement(MovementVo movementVo, MultipartFile[] imageContent){
        log.info("圈子 - 用户发布动态");
        movementService.addMovements(movementVo,imageContent);
        return ResponseEntity.ok(null);
    }

    /**
     *  个人动态
     * @param page 每个码数
     * @param pageSize 每页条数
     * @param userId 当前用户id
     * @return ResponseEntity
     */
    @GetMapping("/all")
    public ResponseEntity findPageMovement(@RequestParam(value = "page", defaultValue = "1") Long page, @RequestParam(value = "pagesize", defaultValue = "10") Long pageSize, Long userId) {
        log.info("好友动态: page : {},pageSize : {},userId : {}",page,pageSize,userId);
        return ResponseEntity.ok(movementService.findPageMovement(page, pageSize, userId));
    }

    /**
     *  圈子 - 好友动态
     * @param page 每个码数
     * @param pagesize 每页条数
     * @return ResponseEntity
     */
    @GetMapping
    public ResponseEntity findFriendPageMovements(@RequestParam("page") Long page, @RequestParam("pagesize") Long pagesize){
        return ResponseEntity.ok(movementService.findFriendPageMovements(page,pagesize));
    }

    /**
     *  圈子 - 推荐动态
     * @param page 每个码数
     * @param pagesize 每页条数
     * @return ResponseEntity
     */
    @RequestMapping(path = "/recommend",method = RequestMethod.GET)
    public ResponseEntity findRecommendPageMovements(@RequestParam(value = "page",defaultValue = "1") Long page, @RequestParam(value = "pagesize",defaultValue = "10") Long pagesize){
        return ResponseEntity.ok(movementService.findRecommendPageMovements(page,pagesize));
    }

    /**
     *  圈子 - 评论动态点赞
     * @param likeId 点赞
     * @return
     */
    @RequestMapping(path = "/{id}/like",method = RequestMethod.GET)
    public ResponseEntity like(@PathVariable("id") String likeId){
        return ResponseEntity.ok(movementService.like(likeId));
    }

    /**
     *  圈子 - 评论动态取消点赞
     * @param likeId 取消点赞
     * @return
     */
    @RequestMapping(path = "/{id}/dislike",method = RequestMethod.GET)
    public ResponseEntity dislike(@PathVariable("id") String likeId){
        return ResponseEntity.ok(movementService.dislike(likeId));
    }

    /**
     *  圈子 - 单挑动态
     * @param movementId 动态id
     * @return MovementsVo
     */
    @GetMapping("/{id}")
    public ResponseEntity findByMovement(@PathVariable("id") String movementId){
        return ResponseEntity.ok(movementService.findByMovement(movementId));
    }

    /**
     *  圈子 - 动态喜欢
     * @param loveId 标识
     * @return 总条数
     */
    @RequestMapping(path = "/{id}/love",method = RequestMethod.GET)
    public ResponseEntity love(@PathVariable("id") String loveId){
        return ResponseEntity.ok(movementService.love(loveId));
    }

    /**
     *  圈子 - 动态不喜欢
     * @param loveId 标识
     * @return 总条数
     */
    @RequestMapping(path = "/{id}/unlove",method = RequestMethod.GET)
    public ResponseEntity unlove(@PathVariable("id") String loveId){
        return ResponseEntity.ok(movementService.unlove(loveId));
    }

    /**
     *  首页 - 谁看过我
     * @return List<VisitorsVo>
     */
    @GetMapping("/visitors")
    public ResponseEntity findVisitors(){
        return ResponseEntity.ok(movementService.findVisitors());
    }

}
